# coding=utf-8

import sys
import importlib

import rdb
import json

reload(sys)
# sys.setdefaultencoding('utf8')


def test():
    return rdb.test()


def song():
    data = rdb.song()
    response = json.dumps(data)
    return response


def json_serial(obj):
    from datetime import date, datetime
    if isinstance(obj, (datetime, date)):
        serial = obj.isoformat()
        return serial
    raise TypeError ("Type %s not serializable" % type(obj))


def query(sql, args=()):
    data = rdb.query(sql, args)
    response = json.dumps(data, default=json_serial)
    return response
